package steed.sample.action;

import java.io.File;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;

import steed.action.BaseAction;
import steed.action.annotation.Power;
import steed.util.file.AttachmentUtil;

@Namespace("/file")
@ParentPackage(value="steed")
@InterceptorRefs({@InterceptorRef(value="mydefault")})
public class UploadFileAction extends BaseAction{
	private File file;
	private String fileFileName;
	private String key = "testFile";
	
	public String getKey() {
		return key;
	}
	public void setKey(String key) {
		this.key = key;
	}
	public File getFile() {
		return file;
	}
	public void setFile(File file) {
		this.file = file;
	}
	public String getFileFileName() {
		return fileFileName;
	}
	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}
	
	@Action("upload")
	public void upload(){
		writeString(AttachmentUtil.getFileEngine().upload("testFile", file, fileFileName));
	}
	@Action("getFiles")
	public void getFiles(){
		writeString(AttachmentUtil.getFileEngine().getFile(key).getAbsolutePath());
	}
	@Action("delete")
	public String delete(){
		AttachmentUtil.getFileEngine().delete(key);
		return null;
	}
}
